package com.congee02.modelshellmvn;

import com.alibaba.fastjson.JSON;
import com.congee02.modelshellmvn.client.PlateRecognitionClient;
import com.congee02.modelshellmvn.entity.account.Account;
import com.congee02.modelshellmvn.entity.plate.vo.PlateRecognitionResult;
import com.congee02.modelshellmvn.exception.DuplicateUsernameException;
import com.congee02.modelshellmvn.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.io.ClassPathResource;

import java.util.List;

@SpringBootApplication
@EnableAspectJAutoProxy
@Slf4j
public class ModelShellMvnApplication {

    @Bean
    public CommandLineRunner commandLineRunner(AccountService accountService) {
        return args -> {
            try {
                accountService.register(
                        new Account()
                                .setUsername("Test")
                                .setPassword("Test")
                );
            } catch (DuplicateUsernameException ignored) {
                log.info("Test account has been registered.");
            }
        };
    }

    @Bean
    public CommandLineRunner T(PlateRecognitionClient  client) {
        return args -> {
            List<PlateRecognitionResult> results = client.recognize(
                    new ClassPathResource(
                            "img_1.png"
                    )
            );
            log.info("{}", JSON.toJSONString(results, true));
        };
    }

    public static void main(String[] args) {
        SpringApplication.run(ModelShellMvnApplication.class, args);
    }

}
